﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace Api.WebForm.HttpModules
{
    public class MyModule : IHttpModule
    {
        /// <summary>
        /// ASP.NET实现页面路由的核心HttpModule
        /// </summary>
        private RouteCollection routes
        {
            get
            {
                return RouteTable.Routes;
            }
        }

        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            context.PostResolveRequestCache += context_PostResolveRequestCache;
        }

        void context_PostResolveRequestCache(object sender, EventArgs e)
        {
            var application = sender as HttpApplication;
            var context = new HttpContextWrapper(application.Context);
            var routeData = routes.GetRouteData(context);
            var requestContext = new RequestContext(context, routeData);
            var handler = routeData.RouteHandler.GetHttpHandler(requestContext);
        }
    }
}